package com.example.myapplication.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;

import android.util.AttributeSet;
import android.view.View;

/**
 *
 * Created by Lx on 2018/6/22.
 */

public class TestView09 extends View {
    float mH, mW;
    Path path;
    Paint paint;
    PathMeasure measure1;
    Path dst;

    public TestView09(Context context) {
        super(context);
    }

    public TestView09(Context context,  AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.RED);
        measure1 = new PathMeasure();
        path = new Path();
        dst = new Path();
    }

    public TestView09(Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mH = h;
        mW = w;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(mW / 2, mH / 2);
        path.addRect(-100, -100, 100, 100, Path.Direction.CW);
        measure1.setPath(path, false);
        measure1.getSegment(100, 300, dst, true);
        canvas.drawPath(dst, paint);
    }
}